Java Conversion of byte[] into a srting and then back to a byte[]

Posted by Sid on Stack Overflow See other posts from Stack Overflow or by Sid
Published on 2010-05-03T14:16:54Z Indexed on 2010/05/03 14:28 UTC
Read the original article Hit count: 292

Filed under:
|
|
|

I am working on a proxy server. I am getting data in byte[] which i convert into a string to perform certain operations. Now when i convert this new string back into a byte [] it causes unkonw problems.

So mainly its like i need to know how to correctly convert a byte[] into a string and then back into a byte[] again.

I tried to just convert the byte[] to string and then back to byte[] again (to make sure thats its not my operations that are causing problems).

So its like:

// where reply is a byte[]

String str= new String(reply,0, bytesRead); streamToClient.write(str.getBytes(), 0, bytesRead);

is not equivalent to

streamToClient.write(reply, 0, bytesRead);


my proxy works fine when i just send the byte[] without any conversion but when i convert it from byte[] to a string and then back to a byte[] its causes problems.

can some one please help? =]

© Stack Overflow or respective owner

Related posts about java

Related posts about bytearray